clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

******************************************************************************************
********************************** Table S1: Data sources and summary statistics
******************************************************************************************

// National poverty rate 
use "${date}/_data/spid_for_analysis_v2.dta", clear

collapse (mean) poor215 poor365 poor685, by(code year)

su poor215 poor365 poor685
distinct code if poor215!=.

// Subnational poverty rate 

use "${date}/_data/spid_for_analysis_v2.dta", clear

su poor215 poor365 poor685
distinct code if poor215!=.

// Chronic poverty
use "${date}/_data/spid_for_analysis_v2.dta", clear

sort geo_code2_new year

bysort geo_code2_new: gen n = _n
bysort geo_code2_new: gen duration = _N

* Chronic poverty measures: poor215 
gen incidence = mean2017 <= 2.15
bysort geo_code2_new: egen poor215_chro_1 = total(incidence)
gen poor215_chro_2 = poor215_chro_1/duration * 100

bysort geo_code2_new: egen poor215_chro_3 = mean(poor215)

bysort geo_code2_new (year): gen incidence_1styear = poor215 if _n==1
	bysort geo_code2_new (year): ereplace incidence_1styear = mean(incidence_1styear)
bysort geo_code2_new (year): gen incidence_lastyear = poor215 if _n==_N
	bysort geo_code2_new (year): ereplace incidence_lastyear = mean(incidence_lastyear)
egen poor215_chro_4 = rowmean(incidence_1styear incidence_lastyear)

bysort geo_code2_new: egen mean_income = mean(mean2017)
gen poor215_chro_5 = mean_income

keep if n==1

drop sample
qui reghdfe poor215_chro_3 temp rainfall_sum humid duration, a(code) cl(geo_code2_new)
gen sample = e(sample)

local depvars poor215_chro_3 poor215_chro_1 poor215_chro_2  poor215_chro_4 poor215_chro_5

su `depvars' if sample==1
distinct code if sample==1


// National inequality 
use "${date}/_data/spid_for_analysis_v2.dta", clear

collapse (mean) gini theil, by(code year)

su gini theil 
distinct code if gini!=.

// Subnational inequality 
use "${date}/_data/spid_for_analysis_v2.dta", clear

su gini theil 
distinct code if gini!=.

// Satellite weather data (1979–2022)
use "${date}/_data/spid_for_analysis_v2.dta", clear

su temp rainfall_sum humid

distinct code if temp!=.

// Mechanisms
use "${date}/_data/spid_for_analysis_v2.dta", clear

su ndvi soil

distinct code if ndvi!=.
distinct code if soil!=.

// Heterogeneity analysis variables
use "${date}/_data/spid_for_analysis_v2.dta", clear

su i.rank_democracy 
distinct code if rank_democracy!=.

su indexagri indexmanu indextrade

// Other country-level characteristics 

use "${date}/_data/spid_for_analysis_v2.dta", clear

collapse (mean) ln_GDPppp Unempilo agri manuf edupri eduter popgr tech, by(code year)

su ln_GDPppp Unempilo agri manuf edupri eduter popgr tech
